package engine.input;

import java.util.ArrayList;

import engine.event.key.JKeyLongPressedEvent;
import engine.event.key.JKeyPressedEvent;
import engine.event.key.JKeyReleasedEvent;
import engine.event.key.JKeyboardListener;
import engine.event.mouse.JMouseListener;
import engine.event.mouse.JMouseMovedEvent;
import engine.event.mouse.JMousePressedEvent;
import engine.event.mouse.JMouseReleasedEvent;
import engine.event.mouse.JMouseWheelEvent;



public class JDisplay 
{
	private ArrayList<JMouseListener> mouseListener = new ArrayList<JMouseListener>();
	private ArrayList<JKeyboardListener> keyListener = new ArrayList<JKeyboardListener>();

	public void fireMousePressedEvent(int mouseX, int mouseY, int button)
	{
		JMousePressedEvent e = new JMousePressedEvent(mouseX, mouseY,button);
		for (JMouseListener listener : mouseListener) {
			listener.mousePressed(e);
		}
	}

	public void fireMouseReleasedEvent(int mouseX, int mouseY, int button)
	{
		JMouseReleasedEvent e = new JMouseReleasedEvent(mouseX, mouseY,button);
		for (JMouseListener listener : mouseListener) {
			listener.mouseReleased(e);
		}
	}

	public void fireMouseWheel(int mouseX, int mouseY, boolean up, int rotation)
	{
		JMouseWheelEvent e = new JMouseWheelEvent( mouseX, mouseY,rotation, up);
		for (JMouseListener listener : mouseListener) {
			listener.mouseWheel(e);
		}
	}

	public void fireMouseMovedEvent(int mouseX, int mouseY)
	{
		JMouseMovedEvent e = new JMouseMovedEvent( mouseX, mouseY);
		for (JMouseListener listener : mouseListener) {
			listener.mouseMoved(e);
		}
	}
	public void fireKeyPressedEvent(int key,char c)
	{
		JKeyPressedEvent e = new JKeyPressedEvent(key,c);
		for (JKeyboardListener listener : keyListener) {
			listener.keyPressed(e);
		}

	}
	public void firekeyReleased(int key,char c)
	{
		JKeyReleasedEvent e= new JKeyReleasedEvent(key,c);
		for (JKeyboardListener listener : keyListener) {
			listener.keyReleased(e);
		}
	}
	public void firekeyLongPressed(int key,char c)
	{
		JKeyLongPressedEvent e= new JKeyLongPressedEvent(key,c);
		for (JKeyboardListener listener : keyListener) {
			listener.keyLongPressed(e);
		}
	}
	public void addMouseEventListener(JMouseListener listener)
	{
		mouseListener.add(listener);
	}

	public void removeMouseEventListener(JMouseListener listener)
	{
		mouseListener.remove(listener);
	}
	
	public void addKeyEventListener(JKeyboardListener listener)
	{
		keyListener.add(listener);
	}
	
	public void removeKeyEventListener(JKeyboardListener listener)
	{
		keyListener.remove(listener);
	}
}
